{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加Banner</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" name="add_article" id="add_article" enctype="multipart/form-data">

                        <div class="form-group">
                            <label class="col-sm-3 control-label">标题：</label>
                            <div class="input-group col-sm-4">
                                <input id="title" type="text" class="form-control" name="title" placeholder="输入课程标题">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label cyanse">所属分类：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="cate_id" id="detail_type">
                                    <option value="1">活动详情</option>
                                    <option value="2">课程详情</option>
                                    <option value="3">H5连接</option>
                                    <option value="4">机构详情</option>
                                    <option value="5">资讯详情</option>
                                    <option value="6">图文详情</option>
                                </select>
                                <a id="myCeditors" style="color:#A94543"></a>
                            </div>
                        </div>
                        <div class="form-group" id="MyType">
                            <label class="col-sm-3 control-label cyanse">所属分类：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="type_name" id="type_name">
                                    {volist name="list" id="vo"}
                                    <option value="{$vo.id}">{$vo.activity_name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">图片：</label>
                            <div class="input-group col-sm-5">
                                <input type="hidden" id="data_photo" name="images" >
                                <div id="imgPicker" style="float:left">选择图片</div>
                                <img id="img_data" height="100px" style="float:left;margin-left: 50px;margin-top: -10px;cursor:pointer;" src="/static/admin/images/no_img.jpg" onclick='imgDisplay(this)'/>
                                <div id="fileList" class="uploader-list" style="float:right"></div>
                            </div>
                        </div>
                        <div class="form-group" style="display: none" id="MyContent">
                            <label class="col-sm-3 control-label cyanse" for="myEditor">内容：</label>
                            <div class="input-group col-sm-9">
                                <textarea name="content" style="width:90%" id="myEditor"></textarea>
                                <a id="myEditors" style="color:#A94543"></a>
                            </div>
                        </div>
                        <div class="form-group" style="display:none"id="MyLink">
                            <label class="col-sm-3 control-label">H5连接：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" name="link" id="link" class="form-control" >
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary btsave"  type="button"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript">
    //上传图片
    wk.upload("{:url('Upload/upload')}",2);

    //百度富文本编辑器
    var editor = UE.getEditor('myEditor', {
        initialFrameHeight:450,
        autoHeight: false,
        autoHeightEnabled:false,
        autoFloatEnabled:false
    });
</script>
<script>
    $("#detail_type").on('change',function () {
        var type_val = $(this).val();
        if(type_val==3){
            $("#MyLink").show();
            $("#MyType").hide();
            $("#MyContent").hide();
        }else if(type_val==6){
            $("#MyLink").hide();
            $("#MyType").hide();
            $("#MyContent").show();
        }else{
            $("#MyLink").hide();
            $("#MyType").show();
            $("#MyContent").hide();
            $.ajax({
                url: "{:url('selectType')}",
                type: "post",
                data:{'type_val':type_val},
                success:function (data) {
                    var  html = '';
                    $("#type_name").html("");

                    if(data.code==1){
                       for (var i=0;i<data.data.length;i++)
                       {
                        html +="<option value='"+data.data[i].id+"'>"+data.data[i].activity_name+"</option>";
                       }
                   }else if (data.code==2){
                       for (var i=0;i<data.data.length;i++)
                       {
                           html +="<option value='"+data.data[i].id+"'>"+data.data[i].classroom_title+"</option>";
                       }
                   }else if(data.code==4){
                       for (var i=0;i<data.data.length;i++)
                       {
                           html +="<option value='"+data.data[i].mechanism_id+"'>"+data.data[i].mechanism_name+"</option>";
                       }
                   }else if(data.code==5){
                       for (var i=0;i<data.data.length;i++)
                       {
                           html +="<option value='"+data.data[i].information_id+"'>"+data.data[i].information_title+"</option>";
                       }
                   }
                    $("#type_name").append(html);
                    $("#type_name").trigger("chosen:updated");
                }
            })
        }
    })
    $(".btsave").on('click',function () {
        var formData = new FormData($("#add_article" )[0]);
        $.ajax({
            url: "{:url('add')}",
            type: "post",
            dataType: "json",
            async: false,//1，这四个要写上，否则点击没反应
            cache: false,//2
            contentType: false,//3
            processData: false,//4
            data: formData,
            success: function (data) {
                if (data.code == 200) {
//                    window.location.href = 'admin/banner/index';
                    wk.success(data.msg,1,"{:url('banner/index')}");
                } else if(data.code == 100){
                    $('.btn').removeAttr('disabled');
                    wk.error(data.msg,2,'');
                    return false;
                }
            }
        });
    })
</script>
</body>
</html>